﻿@model Inscriptionem.Areas.Inscriptionem.Models.Views.SectionCollectionViewModel

@{
    ViewBag.Title = "Inscriptionem » Sections » Order";
    Layout = "../Shared/Layout.cshtml";

    ViewBag.CurrentPage = "Sections";

    var message = string.Empty;
    
    switch(Model.Error)
    {
        case Inscriptionem.Areas.Inscriptionem.Models.Enums.OrderError.OrderNotValid:
        {
            message = "Please enter valid order, a positive number.";
            break;
        }

        case Inscriptionem.Areas.Inscriptionem.Models.Enums.OrderError.OrderDuplicate:
        {
            message = "Entered orders contains duplicates, please enter different value.";
            break;
        }
            
        case Inscriptionem.Areas.Inscriptionem.Models.Enums.OrderError.Other :
        {
            message = "Unknown error occurred, please try again.";
            break;
        }
    }
}

<div class="outer" id="contentwrap">
    @{Html.RenderPartial("NavigationMenu");}
    <div class="postcont">
		<div id="content">
            <div class="post type-post status-publish format-standard hentry">
                <h2 class="title">Order</h2>
                <div class="postdate-single error-message">@message</div>
                <form method="post" action="/Inscriptionem/Section/Order">
                    <table width="100%">
                        <thead>
                            <tr class="postdate">
                                <td>Order</td>
                                <td>Section</td>
                                <td>Section Name</td>
                                <td>Is Default</td>
                                <td>Language</td>
                                <td>Language Name</td>
                            </tr>
                        </thead>
                        <tbody>
                        @{int iterator = 0;}
                        @foreach (var section in Model.Sections.OrderBy(s => s.Language.ID).ThenBy(s => s.ID))
                        {
                        <text>
                        <tr>
                            <td>
                                <fieldset style="border: none; margin: 0px; padding: 0px;">
                                    <input type="hidden" name="sections[@(iterator)].ID" value="@(section.ID)" />
                                    <input type="hidden" name="sections[@(iterator)].Language" value="@(section.Language.ID)" />
                                    <input type="text" name="sections[@(iterator)].Order" value="@(section.Order)" style="width: 50px;" />
                                </fieldset>
                            </td>
                            <td>@(section.Name)</td>
                            <td>@(section.LocalizedName)</td>
                            <td><input type="checkbox" @(section.IsDefault ? "checked" : string.Empty) disabled="disabled" /></td>
                            <td>@(section.Language.Name)</td>
                            <td>@(section.Language.LocalizedName)</td>
                        </tr>
                        </text>
                            iterator++;
                        }
                        </tbody>
                    </table>
                    <input type="reset" value="Reset" />&nbsp;|&nbsp;<input type="submit" value="Save" />
                </form>
			</div>
        </div>
	</div>	
</div>
